package org.buptsse.page;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import org.buptsse.entity.User;

import org.buptsse.thread.UpdateUserPhotoThread;
import org.buptsse.ui.MySettingActivity;
import org.buptsse.ui.R;
import org.buptsse.ui.TestActivity;
import org.buptsse.utils.GloableInstance;
import org.buptsse.utils.ImageService;

import android.app.AlertDialog;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.provider.MediaStore;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;

public class MyPhotoPage extends LinearLayout implements OnClickListener {
	private final String SAVE_PATH = "/mnt/sdcard/tmp/";
	private View viewpersonal;
	private User user = null;
	private Context context;
	private MySettingActivity msa;
	
	
	private ImageView userPhoto,addButton = null;
	private Drawable temp;

	public MyPhotoPage(Context context, AttributeSet attrs) {
		super(context, attrs);
		init();
	}

	public MyPhotoPage(Context context, MySettingActivity msa) {
		super(context);
		this.context = context;
		this.msa=msa;
		init();
	}

	private void init() {
		LayoutInflater inflater = LayoutInflater.from(getContext());
		viewpersonal = inflater.inflate(R.layout.lmy_setting_photo, null);
		

		LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT,
				LayoutParams.FILL_PARENT);
		addView(viewpersonal, params);
		userPhoto=(ImageView) findViewById(R.id.user_photo);
		addButton=(ImageView) findViewById(R.id.add_new);
		addButton.setOnClickListener(this);
	}

	
	
	@Override
	public void onClick(View v) {
		Intent it = new Intent();
		switch (v.getId()) {
		case R.id.add_new:
			//修改头像按钮
			msa.ChooseImage();
			break;
		}
	}
	
	public void setPhoto()
	{
		userPhoto.setImageBitmap(ImageService.getImageByUrl(GloableInstance.user.getPhoto()));
	}
	
	public void setNewPhoto(Bitmap bitmap)
	{
		temp=userPhoto.getDrawable();
		userPhoto.setImageBitmap(bitmap);
	}
	
	public void resetPhoto()
	{
		if(temp!=null)
			userPhoto.setImageDrawable(temp);
	}

}
